using System.IO; 

// '' -----------------------------------------------------------------------------
// '' Project	 : BizBloxTests
// '' Class	 : BizBlox.BizBloxTests.TestSetup
// '' 
// '' -----------------------------------------------------------------------------
// '' <summary>
// '' Create dataset for running tests without the use of the BizBlox class.
// '' </summary>
// '' <remarks>
// '' </remarks>
// '' <history>
// '' 	[cinj]	15/07/2004	Created
// '' </history>
// '' -----------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using pixolut.BizBlox; 

namespace BizBloxTests
{

    public class Setup  
    {
        public static Random rand = new Random();
        public static readonly int LargeDSStudentAndLunchOrderCount = 5000;
        public static readonly int LargeDSFoodCount = 51;

        public static void CreateDataSet()
        {
            CreateDataSet(LargeDSFoodCount, LargeDSStudentAndLunchOrderCount);
        }


        public static void CreateDataSet(int foodCount, int studentAndLunchOrderCount)
        {

            Console.WriteLine( "Enter Setup.CreateDataSet() [please wait...]" ); 
            Console.Out.Flush(); 
            DBAccess dObj = new DBAccess(); 
            Guid[] foodUid = new Guid[ foodCount ]; 
            for ( int i=0; i <= foodUid.Length - 1; i++ ) 
            { 
                foodUid[i] = Guid.NewGuid(); 
                dObj.RunSQL( "INSERT INTO [Food](FoodID, Name, Price)VALUES('" + foodUid[i].ToString() + "','" + ComposeFoodName() + "','" + System.Convert.ToString( System.Convert.ToDouble( rand.NextDouble() * 6 ) ) + "')", CommandType.Text );
            } 
            
            for ( int i=0; i < studentAndLunchOrderCount ; i++ ) 
            { 
                Guid studentId = Guid.NewGuid(); 
                string studentName = ComposeStudentName( i );
                dObj.RunSQL( "INSERT INTO [Student](StudentID, Name, Email, Age)VALUES('" + studentId.ToString() + "','" + studentName + "','" + ComposeStudentEmail( studentName ) + "', '" + System.Convert.ToString( System.Convert.ToInt32( ( rand.NextDouble() * 10 ) + 10 ) ) + "')", CommandType.Text ); 
                dObj.RunSQL( "INSERT INTO [LunchOrder](LunchOrderID, StudentID, FoodID, dt_OrderDate, Quantity) VALUES('" + Guid.NewGuid().ToString() + "','" + studentId.ToString() + "', '" + foodUid[ (int) (rand.NextDouble() * ( foodUid.Length - 1 )) ].ToString() + "', '" + DateTime.Now.AddDays( rand.NextDouble() * 5 ).ToString( "u" ) + "', '" + System.Convert.ToString( System.Convert.ToInt32( rand.NextDouble() * 4 ) ) + "')", CommandType.Text );
            } 
            Console.WriteLine( "Exit Setup.CreateDataSet()" ); 
            Console.Out.Flush(); 
        } 
        
        
        public static void ClearDataSet() 
        { 
            Console.WriteLine( "Enter Setup.ClearDataSet()" ); 
            DBAccess dObj = new DBAccess(); 
            dObj.RunSQL( "DELETE FROM [Food]", CommandType.Text ); 
            dObj.RunSQL( "DELETE FROM [Student]", CommandType.Text ); 
            dObj.RunSQL( "DELETE FROM [LunchOrder]", CommandType.Text ); 
            Console.WriteLine( "Exit Setup.ClearDataSet()" ); 
        } 
        
        
        private static string ComposeFoodName() 
        { 
            string[] foodSuffix = { "pie", "roll", "souffle", "pasta", "sandwich", "soup", "vinegarette", "salad", "dip with asparagus", "chicken puree tart", "and mushroom" }; 
            string name = Dictionary.Entry(rand.Next(Dictionary.Count()-1)) + " " + foodSuffix[ (int) (rand.Next(foodSuffix.Length - 1)) ];
            //Console.WriteLine("Food:" + name);
            return name; 
        } 
        
        
        private static string ComposeStudentName( int i ) 
        {
            string name = Dictionary.Entry(rand.Next(Dictionary.Count() - 1)) + " " + Dictionary.Entry(rand.Next(Dictionary.Count() - 1)); 
            // Console.WriteLine("Student:" & name)
            return name; 
        } 
        
        
        private static string ComposeStudentEmail( string name ) 
        { 
            string prefix = name.Replace( " ", "_" ); 
            string[] webSuffix = { "com", "edu", "gov", "mil", "org" };
            string mail = prefix + "@" + Dictionary.Entry(rand.Next(Dictionary.Count() - 1)) + "." + webSuffix[(int)(rand.Next(webSuffix.Length - 1))]; 
            // Console.WriteLine("Email:" & mail)
            return mail; 
        } 
        
        
        
        internal const int TestObjectAge = 21; 
        internal const string TestObjectName = "Joe Cincotta"; 
        internal const string TestObjectEmail = "joe@pixolut.com"; 
        internal const string TestObjectFoodName = "shrimp"; 
        internal const double TestObjectFoodPrice = 1.23; 
        
        internal static Student CreateTestStudent() 
        { 
            Console.WriteLine( "Enter Setup.CreateTestStudent()" ); 
            Student Obj = new Student(); 
            Obj.Age = TestObjectAge; 
            Obj.Name = TestObjectName; 
            Obj.Email = TestObjectEmail; 
            Obj.Save(); 
            return Obj; 
        }

        internal static Food CreateTestFood()
        {
            Console.WriteLine("Enter Setup.CreateTestFood()");
            Food fObj = new Food();
            fObj.Name = TestObjectFoodName;
            fObj.Price = TestObjectFoodPrice;
            fObj.Save();
            return fObj;
        } 

        internal static Food CreateTestFood(double price) 
        { 
            Console.WriteLine( "Enter Setup.CreateTestFood(price)" ); 
            Food fObj = new Food(); 
            fObj.Name = TestObjectFoodName; 
            fObj.Price = price; 
            fObj.Save(); 
            return fObj; 
        }


        internal static Food CreateTestFood(string name, double price)
        {
            Console.WriteLine("Enter Setup.CreateTestFood(name,price)");
            Food fObj = new Food();
            fObj.Name = name;
            fObj.Price = price;
            fObj.Save();
            return fObj;
        }
        
    } 
    
    
} 
